enyo.kind({
    name: "MyApps.GolfClubDetail",
    kind: enyo.VFlexBox,
    events: {
        onBack: "",
    },
    components: [    /**
     * Services
     */
    {
        name: "getGolfData",
        kind: "WebService",
        onSuccess: "gotGolfData",
        onFailure: "gotGolfDataFailure"
    }, {
        name: "pane",
        kind: "Pane",
        flex: 1,
        className: "golfclubdetail",
        components: [{
            kind: "VFlexBox",
            onSelectedView: "viewSelected",
            components: [{
                kind: "PageHeader",
                className: "enyo-header-dark",
                components: [{
                    kind: "IconButton",
                    onclick: "doBack",
                    icon: "images/menu-icon-back.png",
                    className: "enyo-button-dark"
                }, {
                    kind: "VFlexBox",
                    flex: 1,
                    align: "center",
                    components: [{
                        name: "titleViewDetails",
                        content: "Golf"
                    }, ]
                }, {
                    kind: "Button",
                    content: "Carte",
                    className: "enyo-button-dark",
                    onclick: "viewMap"
                }, ]
            }, {
                kind: "Scroller",
                flex: 1,
                components: [{
                    kind: "RowGroup",
                    defaultKind: "HFlexBox",
                    caption: "Adresse",
                    components: [{
                        name: "adresse1"
                    }, {
                        name: "adresse2"
                    }]
                }, {
                    kind: "RowGroup",
                    defaultKind: "HFlexBox",
                    caption: "Contact",
                    components: [{
                        name: "tel"
                    }, {
                        name: "fax"
                    }, {
                        name: "mail"
                    }, {
                        name: "web"
                    }]
                }, {
                    kind: "Group",
                    caption: "Les Pros",
                    components: [{
                        name: "list",
                        kind: "VirtualRepeater",
                        flex: 1,
                        onSetupRow: "listSetupRow",
                        components: [{
                            kind: "Item",
                            layoutKind: "HFlexLayout",
                            components: [{
                                name: "photo",
                                kind: "Image",
                                className: "photo",
                            
                            }, {
                                kind: "VFlexBox",
                                components: [{
                                    name: "name",
                                    className: "partnername",
                                }, {
                                    name: "phone",
                                    className: "partnertel",
                                }, ]
                            }, {
                                name: "logo",
                                kind: "Image",
                            }],
                        }]
                    }, ]
                }, ]
            
            }, ]
        },        /**
         * Components definition
         */
        {
            name: "showOnMapView",
            kind: "MyApps.PointOnMap",
            onBack: "goBack"
        }, ]
    }, ],
    
    create: function(){
        this.inherited(arguments);
        this.golfpros = [];
    },
    setGolf: function(selgolf){
        this.$.getGolfData.setUrl("http://golfplus.mobile2you.fr/golfs/" + selgolf.golf.id + ".json");
        this.$.getGolfData.call();
        this.$.pane.render();
    },
    
    gotGolfData: function(inSender, inResponse){
        this.golfData = inResponse;
        this.golfpros = inResponse.golf.golf_pros;
        this.$.titleViewDetails.setContent(this.golfData.golf.nom);
        this.$.adresse1.setContent(this.golfData.golf.adresse);
        this.$.adresse2.setContent(this.golfData.golf.cp + " " + this.golfData.golf.ville);
        this.$.tel.setContent("Tel: " + this.golfData.golf.tel);
        this.$.fax.setContent("Fax: " + this.golfData.golf.fax);
        this.$.mail.setContent(this.golfData.golf.mail);
        this.$.web.setContent(this.golfData.golf.web);
        this.$.pane.render();
    },
    
    gotGolfDataFailure: function(inSender, inResponse){
        console.log("failure from getGolfData");
    },
    listSetupRow: function(inSender, inRow){
    
        var f = this.golfpros[inRow];
        if (f) {
            this.$.photo.setSrc("http://golfplus.mobile2you.fr/images/" + f.thumb)
            this.$.name.setContent(f.prenom + " " + f.nom);
            this.$.phone.setContent(f.tel);
            return true;
        }
    },
    goBack: function(inSender, inEvent){
        this.$.pane.back(inEvent);
    },
    
    viewMap: function(){
        this.$.pane.selectViewByName("showOnMapView");
        this.$.showOnMapView.showOnMap(this.golfData.golf.latitude, this.golfData.golf.longitude, this.golfData.golf.nom);
    },


});



